<template>
  <section class="container">
    <div>
      <button class="button is-primary" @click="login">登录</button>
      <nuxt-link to="/account"> account</nuxt-link>
    </div>
  </section>
</template>

<script>
  import cookies from '../assets/js/common/cookies';
  import NuxtLink from "../.nuxt/components/nuxt-link";

  export default {
    data () {
      return {
        single: false
      }
    },
    components: {
      NuxtLink
    },
    methods: {
      login({}) {
        this.doLogin();
      },
      async doLogin() {
        let res = await this.$axios.post('/auth', {"userName": "admin" , "password": "admin"});
        console.log(res);
        let token = res.data.token;

        this.$store.commit('SET_TOKEN', token);
        cookies.setToken(token);
        this.$router.push('/account');
      }
    }
  }
</script>

<style>

</style>
